# encoding: utf-8

# 常用功能性函数的集合

# 网站搜索,默认搜索项目，search_user为true是搜索用户
def web_search(keyword, search_user = false)
  @driver.get(@base_url+'search')
  @driver.find_element(:id, "search").send_keys keyword
  @driver.find_element(:xpath, "//button[@type='submit']").click

  if (search_user) then
    @driver.find_element(:id, "search_user").click
  end
end

# 判断该参数是否为hash，如果是hash类型，则取其中某个键的值
def get_hash(hash, key)
  hash.class == Hash ? hash["#{key}"] : hash
end

# 代码比较
def code_compare(from, to)
  @driver.find_element(:id, "from").send_keys from
  @driver.find_element(:id, "to").send_keys to

  @driver.find_element(:xpath, "//input[@type='submit']").click
end

# 查看页面是否正常(默认判断页面正常)
def page_open_should_normal(is_logo = true)
  if is_logo then
    element_present?(:css, ".logo.pull-left").should be_true
  else
    element_present?(:css, ".logo.pull-left").should be_false
  end
end

# 帮助定为页面元素使用
class Selenium::WebDriver::Element
  def flash
    @bridge.executeScript(high_light_script, self)
  end #flash

  def high_light_script
    'arguments[0].style.border = "3px solid red"'
  end #high_light_script
end